package demo06_Callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author kunkun
 * @className TestCallable
 * @Description 测试Callable接口
 * @date 2025/3/6 10:25
 */
public class TestCallable {
    public static void main(String[] args) {
        // 1. 填装适配器
        FutureTask<Integer> futureTask = new FutureTask<Integer>(new A());

        // 2. 执行任务
        new Thread(futureTask).start();

        //3. 获取结果
        try {
            System.out.println("result: " + futureTask.get());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }



    static class A implements Callable<Integer> {

        @Override
        public Integer call() throws Exception {
            System.out.println("A.call()");
            return 1024;
        }
    }
}
